-module(interpreter_block).
-include_lib("nitrogen/include/wf.inc").
-include("src/handling/useful.hrl").
-compile(export_all).

						%Builders
assemble_header(X) ->
    X.

assemble_menu(X) ->
    X.

assemble_body(X) ->
    X ++ [
	  #p{},
	  #textarea{id=ib_code, class="ib_code"}, #br{},
	  #button{text="Lancer l'évaluation", actions=helper:act(?MODULE, {run_code, body})},%, Caller})},

	  #p{},
	  #table {id=ib_placement, class="ib_table", 
		  rows=[
			#tablerow { cells=[
					   #tablecell { id=ib_output }
					  ]}
		       ]}
	 ].


						%Wiring

wire() ->
    ok.
						%Behavior
behave(_) ->
    ok.
						%Events
event({run_code, _}) ->    
    [Code] = wf:q(ib_code),
    Output = helper:runhertz(?HERTZ_LANG_PATH, Code),
    Module = hglobals:vget(helper:id_me(), caller),

    Module:exec(fun(X) -> wf:insert_top(ib_output, #panel{body=X}) end, Output),
    ok;

event(_) ->
    ok.
